package createThread.cn.tedu.threaddemo.test5;

public class Demo {
    public static int num = 0;

    private static final Object lock = new Object();
    public static void testSync() {
            num++;
    }

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
            for (int i = 1; i <= 50000; i++) {
                synchronized (lock){
                    testSync();
                }
            }
        });
        Thread t2 = new Thread(()->{
            synchronized (lock){
                for (int i = 1; i <= 50000; i++) {
                    testSync();
                }
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println("num " + num);
    }
}
